package com.railway.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.railway.service.UserService;
import com.railway.service.impl.UserServiceImpl;
@WebServlet("/updateUser.do")
public class UpdateUserServlet extends HttpServlet{
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setCharacterEncoding("UTF-8");
		resp.setContentType("application/json");
		req.setCharacterEncoding("UTF-8");
		String user_id = req.getParameter("user_id");
		int userId = Integer.parseInt(user_id);
		String user_name = req.getParameter("user_name");
		String user_password = req.getParameter("user_password");
		String user_phone = req.getParameter("user_phone");
		String user_email = req.getParameter("user_email");
		String consumption_password = req.getParameter("consumption_password");
		UserService us = new UserServiceImpl();
		
		int msg = us.updateUserById(userId, user_name, user_phone, user_password, user_email, consumption_password);
		System.out.println(us.updateUserById(userId, user_name, user_phone, user_password, user_email, consumption_password));
		ObjectMapper om = new ObjectMapper();
		if(msg == 1) {
			resp.getWriter().print("success");
		}
	}
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
}
